#ifndef __OCFEXTLOGIN_H__
#define __OCFEXTLOGIN_H__

#include "memmngr.h"
#include "Job.h"
#include "OcfExtDBInterface.h"

#define DF_LOGINDB		0

////////////////////////////////////////////////////////////////////////////////
//
class COcfExtLogin: public COcfExtImpl
{
public:
	COcfExtLogin(IUnknown *pIUnkOuter, CDllServer *pcDllServer, COcfExtImplBase* pcBase);
	virtual ~COcfExtLogin();

public:
	virtual HRESULT __stdcall fnInit(USHORT uiServerID, ULONG ulMaxBindX, BYTE byServiceType, IUnknown* pISink);
	virtual HRESULT __stdcall fnUninit();
	virtual HRESULT __stdcall fnSetConfigPath(unsigned char* pszCfgPath);
	virtual HRESULT __stdcall fnGetStatus(LONG* plStatus);
	virtual HRESULT __stdcall fnBind(ULONG ulBindX, ULONG ulIdentity, ULONG ulKey);
	virtual HRESULT __stdcall fnUnbind(ULONG ulBindX, ULONG ulIdentity, ULONG ulKey);
	virtual HRESULT __stdcall fnIn(ULONG ulBindX, ULONG ulIdentity, LONG lLen, unsigned char* pchData);
	virtual HRESULT __stdcall fnRequestAnything(LONG lLenQuery, unsigned char* pchQuery, ULONG ulMaxLenRet, LONG* plLenRet, unsigned char* pchRet);

public:
	virtual HRESULT __stdcall QueryInterfaceEx(REFIID iid, void** ppv);

	void Logging(const char* pszFormat, ...);

public:
	inline IOcfDB* GetDbSession(int nIdx) 
	{
		IOcfDB *pOcfDB = NULL;
		m_piDbPool->GetDBConn(nIdx, &pOcfDB);
		return pOcfDB;
	}
	inline void ReleaseDbSession(int nIdx, IOcfDB* piOcfDb)
	{
		m_piDbPool->ReleaseDBConn(nIdx, piOcfDb);
	}

private:
	IOcfDBPool* m_piDbPool;
	CJobCtrlManager<COcfAllocator> m_cDispatchModPool;	
	int m_iJobThreadCount;
};

extern COcfExtLogin* GetOcfExtLoginInstance();

#define LOGIN GetOcfExtLoginInstance()
#define SINK2 LOGIN->GetSinkInterface2()
#define SINK3 LOGIN->GetSinkInterface3()
#define LOGGING LOGIN->Logging

////////////////////////////////////////////////////////////////////////////////
//
class COcfExtLoginMainControlCenter: public CMainControlCenter
{
public:
	COcfExtLoginMainControlCenter(CLSID& clsidComponent, char* pszFriendlyName, char* pszVerIndProgID, char* pszProgID):CMainControlCenter(clsidComponent, pszFriendlyName, pszVerIndProgID, pszProgID) {}
	virtual ~COcfExtLoginMainControlCenter() {}

public:
	virtual COcfExtImpl* CreateComponent(IUnknown *pIUnkOuter, CDllServer *pcDllServer, COcfExtImplBase* pcBase)
	{
		return new COcfExtLogin(pIUnkOuter, pcDllServer, pcBase);
	}
};

#endif
